package com.rt.easyjava.base.biz1.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.rt.easyjava.base.biz1.bean.TmptAuthPositionBiz;
import com.rt.easyjava.base.biz1.dto.TmptAuthPositionBizDto;
import com.rt.easyjava.base.biz1.mapper.TmptAuthPositionBizMapper;
import com.rt.easyjava.base.biz1.service.intf.TmptAuthPositionBizService;
import com.rt.tmpt.service.utils.SpringContextHolder;
import com.rt.easyjava.common.base.Result;
import com.rt.easyjava.common.service.BaseServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.lang.reflect.Method;

/**
 *  服务实现类
 * @author wuxiaoyong
 * @since 2021-05-12
 */
@Slf4j
@Service(value = "tmptAuthPositionService")
@Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
public class TmptAuthPositionBizServiceImpl extends BaseServiceImpl<TmptAuthPositionBizMapper, TmptAuthPositionBiz, TmptAuthPositionBizDto> implements TmptAuthPositionBizService{
    // @Resource private MyMapper mapper;
    // @Resource private TmptAuthPositionBizMapper tmptAuthPositionBizMapper;

    // ==================================================================================
    // ========== 以下使用的是 Mybatis-plus 实现, 适合单表操作 ==============================
    // ==================================================================================

    /**
    * create a object
    * @param tmptAuthPositionBizDto
    * @return
    */
    @Override
    public Result<TmptAuthPositionBizDto> create(TmptAuthPositionBizDto tmptAuthPositionBizDto) {
        return super.create(tmptAuthPositionBizDto, TmptAuthPositionBiz.class);
    }

    /**
    * update a object by Id
    * @param tmptAuthPositionBizDto
    * @param updateWrapper
    * @return
    */
    @Override
    public Result<TmptAuthPositionBizDto> update(TmptAuthPositionBizDto tmptAuthPositionBizDto, UpdateWrapper updateWrapper) {
        return super.update(tmptAuthPositionBizDto, updateWrapper, TmptAuthPositionBiz.class);
    }

    /**
    * 分页 (无合计功能)
    * @param page
    * @param queryWrapper
    * @return
    */
    public Result<TmptAuthPositionBizDto> page(Page<TmptAuthPositionBiz> page, QueryWrapper<TmptAuthPositionBiz> queryWrapper){
        return super.page(page, queryWrapper, TmptAuthPositionBizDto.class);
    }

    /**
    * select all by queryWrapper
    * @param queryWrapper
    * @return
    */
    @Override
    public Result<TmptAuthPositionBizDto> selectBy(QueryWrapper<TmptAuthPositionBiz> queryWrapper) {
        return super.selectBy(queryWrapper, TmptAuthPositionBizDto.class);
    }

    /**
    * select one by id
    * @param id
    * @return
    */
    @Override
    public Result<TmptAuthPositionBizDto> selectById(Serializable id) {
        return super.selectById(id, TmptAuthPositionBizDto.class);
    }


    @Override
    public Result<TmptAuthPositionBizDto> selectDtoListByKey(String columnName, String key) {
        return super.selectDtoListByKey(columnName, key, TmptAuthPositionBizDto.class);
    }



    // ==================================================================================
    // ========== 以下使用的是自定义的 mapper.xml 实现, 适合多表查询 =========================
    // ==================================================================================

    /**
    * 分页查询：mybatis plus 自定义sql分页查询
    * 默认开启合计查询，按需注掉代码
    * @param page
    * @param queryWrapper
    * @return
    */
    @Override
    public Result<TmptAuthPositionBizDto> myPage(Page<TmptAuthPositionBiz> page, QueryWrapper<TmptAuthPositionBiz> queryWrapper) {
        return super.myPage(page, queryWrapper, TmptAuthPositionBizDto.class);
    }

    @Override
    public Result<TmptAuthPositionBizDto> myPage(Page<TmptAuthPositionBiz> page, QueryWrapper<TmptAuthPositionBiz> queryWrapper, Boolean hasFooter) {
        return super.myPage(page, queryWrapper, hasFooter, TmptAuthPositionBizDto.class);
    }

    @Override
    public Result<TmptAuthPositionBizDto> mySelectBy(QueryWrapper<TmptAuthPositionBiz> queryWrapper) {
        return super.mySelectBy(queryWrapper, TmptAuthPositionBizDto.class);
    }

    @Override
    public Result<TmptAuthPositionBizDto> mySelectById(Serializable id) {
        return super.mySelectById(id, TmptAuthPositionBizDto.class);
    }

    @Override
    public Result select4column(String columnName){
        try {
            // vue默认传过来的，出于select option类名考虑，首字母是大写，这样要小字当属性用。
            columnName = columnName.substring(0,1).toLowerCase()+columnName.substring(1);
            Object o = SpringContextHolder.getBean("tmptAuthPositionBizMapper");
            Method method = o.getClass().getMethod("mySelect4"+columnName);
            return Result.builder(method.invoke(o));
        }catch (Exception e){
            throw new RuntimeException("方法名不存在");
        }
    }

}
